Quarto Basics

2023-05-05

1 Polar Axis

For a demonstration of a line plot on a polar axis, see Figure 1

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams.update({
    'axes.facecolor': 'none',
    'figure.facecolor': 'none',
    'savefig.facecolor': 'none',
    'savefig.format': 'svg',
    'axes.edgecolor': 'none',
    'axes.grid': True,
    'axes.labelcolor': '#666',
    'axes.titlecolor': '#666',
    'grid.color': '#666',
    'text.color': '#666',
    'grid.linestyle': '--',
    'grid.linewidth': 0.5,
    'grid.alpha': 0.4,
    'xtick.color': 'none',
    'ytick.color': 'none',
    'xtick.labelcolor': '#666',
    'legend.edgecolor': 'none',
    'ytick.labelcolor': '#666',
    'savefig.transparent': True,
})

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fix, ax = plt.subplots(
    subplot_kw = {'projection': 'polar'}
)
assert isinstance(ax, plt.PolarAxes)
ax.plot(theta, r)
ax.set_rticks([0.5, 1., 1.5, 2.])
ax.grid(True)
plt.show()

Figure 1: A line plot on a polar axis

Warning

In order for a figure to be cross-referenceable, its label must start with the fig- prefix.

2 Plotly

import plotly.express as px
gapminder = px.data.gapminder()
gapminder2007 = gapminder.query('year == 2007')
fig = px.scatter(
    gapminder2007,
    x="gdpPercap",
    y="lifeExp",
    color="continent",
    size="pop",
    size_max=60,
    hover_name="country",
    template="plotly_dark",
)
fig.show()
Figure 2: A plot made using plotly express

3 Jupyter Widgets

from ipyleaflet import Map, Marker, basemaps, basemap_to_tiles
m = Map(
  basemap=basemap_to_tiles(
    basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"
  ),
  center=(52.204793, 360.121558),
  zoom=4
)
m.add_layer(Marker(location=(52.204793, 360.121558)))
m

4 Figures with Subcaptions

import matplotlib.pyplot as plt
plt.plot([1,23,2,4])
plt.show()

plt.plot([8,65,23,90])
plt.show()

(a) First

(b) Second

Figure 3: Charts

5 Mermaid Diagrams

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

6 Block Layout

6.1 List One

  • Item A
  • Item B
  • Item C

6.2 List Two

  • Item X
  • Item Y
  • Item Z

7 Placing Colorbars

Colorbars indicate the quantitative extent of image data. Placing in a figure is non-trivial because room needs to be made for them. The simplest case is just attaching a colorbar to each axes:1.

Code
import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(2, 2, figsize=(16, 12))
assert isinstance(fig, plt.Figure)
cmaps = ['RdBu_r', 'viridis']
for col in range(2):
    for row in range(2):
        ax = axs[row, col]
        pcm = ax.pcolormesh(
          np.random.random((20, 20)) * (col + 1),
          cmap=cmaps[col]
        )
        fig.colorbar(pcm, ax=ax)
ax.grid(False)
plt.show()

8 Extras

Note

Note that there are five types of callouts, including: note, tip, warning, caution, and important.

  • Testing lists
  • Testing
    • Testing
    • Testing again
      • triple Checkboxes
    • Nested lists
      • Checkboxes ??